package com.moji.controller.api;


import com.moji.common.Commons;
import com.moji.common.base.ApiResult;
import com.moji.common.config.OperateLog;
import com.moji.common.entity.MyPage;
import com.moji.entity.SysDept;
import com.moji.entity.dto.PrOnOffDto;
import com.moji.service.SysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 部门设置 前端控制器
 * </p>
 *
 * @author ccl
 * @since 2024-07-23
 */
@RestController
@RequestMapping("/api/sysDept")
@Api(tags = "部门信息", value = "部门信息接口")
public class SysDeptController {

    @Resource
    private SysDeptService sysDeptService;

    @PostMapping("add")
    @ApiOperation("保存部门信息数据")
    @OperateLog(moduleName = "部门管理",content = "保存部门信息",operateType = Commons.OPERATE_TYPE.ADD)
    public ApiResult save(@RequestBody SysDept sysDept){
        return ApiResult.ok(sysDeptService.add(sysDept));
    }

    @PostMapping("update")
    @ApiOperation("编辑机构信息数据")
    @OperateLog(moduleName = "部门管理",content = "编辑部门信息数据",operateType = Commons.OPERATE_TYPE.EDIT)
    public ApiResult update(@RequestBody SysDept sysDept){
        return ApiResult.ok(sysDeptService.edit(sysDept));
    }

    @GetMapping("delete")
    @ApiOperation("删除部门信息数据")
    @ApiImplicitParam(name = "deptCode",value = "机构编码",required = true,dataType = "String")
    public ApiResult delete(Long id){
        return ApiResult.ok(sysDeptService.delete(id));
    }

    @PostMapping("queryPage")
    @ApiOperation("分页查询部门信息数据")
    public ApiResult<MyPage<SysDept>> queryPage(@RequestBody SysDept sysDept){
        MyPage<SysDept> ccpSystemDeptMyPage = sysDeptService.queryPage(sysDept);
        return ApiResult.ok(ccpSystemDeptMyPage);
    }

    @GetMapping("deptSelectBox")
    @ApiOperation("查询部门下拉框数据")
    public ApiResult deptSelectBox(){
        return ApiResult.ok(sysDeptService.queryDeptSelectBox());
    }

    @GetMapping("queryDeptTree")
    @ApiOperation("查询部门树形数据")
    public ApiResult queryDeptTree(){

        return ApiResult.ok(sysDeptService.queryDeptTree());
    }

    @PostMapping("queryPageTree")
    @ApiOperation("分页查询部门树形数据")
    public ApiResult queryPageTree(@RequestBody SysDept sysDept){
        return ApiResult.ok(sysDeptService.queryPageTree(sysDept));
    }

    @PostMapping("updateDeptStatus")
    @ApiOperation("更新部门启停状态")
    public ApiResult updateDeptStatus(@RequestBody PrOnOffDto prOnOffDao){
        return ApiResult.ok(sysDeptService.updateStatus(prOnOffDao));
    }

    @GetMapping("detail")
    @ApiOperation("部门_详情数据")
    public ApiResult detail(Long id){
        return ApiResult.ok(sysDeptService.detail(id));
    }
}

